#include "drawwindow.h"

DrawWindow::DrawWindow(QAxObject * pCad,int windowType,std::map<QString,QString>* data)
{
    this->cad = pCad;
    this->type = windowType;
    this->windowData = data;
}
void DrawWindow::DrawSingleWindow()
{
    //数据

    float upperLBoardLength = windowData->find("IDC_UPPER_LBOARD_LENGTH")->second.toFloat();
    float leftLBoardLength = windowData->find("IDC_LEFT_LBOARD_LENGTH")->second.toFloat();
       float rightLBoardLength = windowData->find("IDC_RIGHT_LBOARD_LENGTH")->second.toFloat();
       float upperLBoardWidth = windowData->find("IDC_UPPER_LBOARD_WIDTH")->second.toFloat();
       float upperBoardLength = windowData->find("IDC_UPPER_BOARD_LENGTH")->second.toFloat();
       float upperBoardWidth = windowData->find("IDC_UPPER_BOARD_WIDTH")->second.toFloat();
       float lboardLHeight = windowData->find("IDC_LBOARD_LHEIGHT")->second.toFloat();
       float upperBoardHeight = windowData->find("IDC_UPPER_BOARD_HEIGHT")->second.toFloat();
       float plainEdgeLength = windowData->find("IDC_PLAIN_EDGE_LENGTH")->second.toFloat();
       float plainEdgeWidth = windowData->find("IDC_PLAIN_EDGE_WIDTH")->second.toFloat();
       float hidePlainEdgeWidth = windowData->find("IDC_HIDE_PLAIN_EDGE_WIDTH")->second.toFloat();
       float windowWidth = windowData->find("IDC_WINDOW_WIDTH")->second.toFloat();
    QAxObject* pDoc = cad->querySubObject("ActiveDocument");
    QAxObject* pModelSpace = pDoc->querySubObject("ModelSpace");
    //float windowSize = 550.6;
    bool isExport = (bool)windowData->find("IDC_IS_EXPORT")->second.toInt();
    QString exportPath = windowData->find("IDC_EXPORT_PATH")->second;
    DrawComponment *dc = new DrawComponment(pModelSpace,this->windowData,1);
    int offset = 500;
    QPointF startPoint_view0(100,100);
    QPointF startPoint_view1(100,100 + offset);
    QPointF startPoint_view2(100 + offset,100 + offset);
    //画俯视图
    dc->DrawLBoard(startPoint_view0,0);
    startPoint_view0 = QPoint(startPoint_view0.x() +  upperLBoardLength - lboardLHeight,startPoint_view0.y() + lboardLHeight);
    dc->DrawEdge(startPoint_view0,0);
    //画正视图
    dc->DrawLBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + (upperLBoardLength - lboardLHeight -  plainEdgeWidth - hidePlainEdgeWidth - windowWidth),startPoint_view1.y() +leftLBoardLength - plainEdgeLength );
    dc->DrawEdge(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + plainEdgeWidth,startPoint_view1.y());
    dc->DrawBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x(),startPoint_view1.y() + upperBoardWidth);
    dc->DrawLeaf(startPoint_view1,1);
    //画侧视图
    dc->DrawLBoard(startPoint_view2,2);
    startPoint_view2 = QPointF(startPoint_view2.x() + upperBoardHeight - lboardLHeight ,startPoint_view2.y() + (leftLBoardLength - plainEdgeLength));
    dc->DrawBoard(startPoint_view2,2);
    dc->DrawLeaf(startPoint_view2,2);
    if (isExport) pDoc->dynamicCall("SaveAs(const QString&)",exportPath);
}
void DrawWindow::DrawDoubleWindow()
{
    float leftLBoardLength = windowData->find("IDC_LEFT_LBOARD_LENGTH")->second.toFloat();
    float upperBoardWidth = windowData->find("IDC_UPPER_BOARD_WIDTH")->second.toFloat();
    float lboardLHeight = windowData->find("IDC_LBOARD_LHEIGHT")->second.toFloat();
    float upperBoardHeight = windowData->find("IDC_UPPER_BOARD_HEIGHT")->second.toFloat();
    float plainEdgeLength = windowData->find("IDC_PLAIN_EDGE_LENGTH")->second.toFloat();
    float hidePlainEdgeWidth = windowData->find("IDC_HIDE_PLAIN_EDGE_WIDTH")->second.toFloat();
    float boardSlotDept = windowData->find("IDC_UPPER_BOARD_SLOT_DEPT")->second.toFloat();

    QAxObject* pDoc = cad->querySubObject("Documents.Add");
    QAxObject* pModelSpace = pDoc->querySubObject("ModelSpace");
    bool isExport = (bool)windowData->find("IDC_IS_EXPORT")->second.toInt();
    QString exportPath = windowData->find("IDC_EXPORT_PATH")->second;
    DrawComponment *dc = new DrawComponment(pModelSpace,this->windowData,2);
    int offset = 500;
    QPointF startPoint_view0(100,100);
    QPointF startPoint_view1(100,100 + offset);
    QPointF startPoint_view2(100 + offset,100 + offset);
    //画俯视图
    dc->DrawLBoard(startPoint_view0,0);
    startPoint_view0 = QPointF(startPoint_view0.x() + lboardLHeight,startPoint_view0.y() + lboardLHeight);
    dc->DrawEdge(startPoint_view0,0);
    //画正视图
    dc->DrawLBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + lboardLHeight,startPoint_view1.y() + lboardLHeight);
    dc->DrawEdge(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + hidePlainEdgeWidth,startPoint_view1.y());
    dc->DrawBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x(),startPoint_view1.y() + upperBoardWidth - boardSlotDept);
    dc->DrawLeaf(startPoint_view1,1);
    //画侧视图
    dc->DrawLBoard(startPoint_view2,2);
    startPoint_view2 = QPointF(startPoint_view2.x() + upperBoardHeight - lboardLHeight ,startPoint_view2.y() + (leftLBoardLength - plainEdgeLength));
    dc->DrawBoard(startPoint_view2,2);
    dc->DrawLeaf(startPoint_view2,2);
    if (isExport) pDoc->dynamicCall("SaveAs(const QString&)",exportPath);
}
void DrawWindow::DrawTripleWindow()
{
    float upperLBoardLength = windowData->find("IDC_UPPER_LBOARD_LENGTH")->second.toFloat();
    float leftLBoardLength = windowData->find("IDC_LEFT_LBOARD_LENGTH")->second.toFloat();
    float rightLBoardLength = windowData->find("IDC_RIGHT_LBOARD_LENGTH")->second.toFloat();
    float upperLBoardWidth = windowData->find("IDC_UPPER_LBOARD_WIDTH")->second.toFloat();
    float upperBoardLength = windowData->find("IDC_UPPER_BOARD_LENGTH")->second.toFloat();
    float upperBoardWidth = windowData->find("IDC_UPPER_BOARD_WIDTH")->second.toFloat();
    float lboardLHeight = windowData->find("IDC_LBOARD_LHEIGHT")->second.toFloat();
    float upperBoardHeight = windowData->find("IDC_UPPER_BOARD_HEIGHT")->second.toFloat();
    float plainEdgeLength = windowData->find("IDC_PLAIN_EDGE_LENGTH")->second.toFloat();
    float plainEdgeWidth = windowData->find("IDC_PLAIN_EDGE_WIDTH")->second.toFloat();
    float hidePlainEdgeWidth = windowData->find("IDC_HIDE_PLAIN_EDGE_WIDTH")->second.toFloat();
    float windowWidth = windowData->find("IDC_WINDOW_WIDTH")->second.toFloat();
    float boardSlotDept = windowData->find("IDC_UPPER_BOARD_SLOT_DEPT")->second.toFloat();

    QAxObject* pDoc = cad->querySubObject("Documents.Add");
    QAxObject* pModelSpace = pDoc->querySubObject("ModelSpace");
    bool isExport = (bool)windowData->find("IDC_IS_EXPORT")->second.toInt();
    QString exportPath = windowData->find("IDC_EXPORT_PATH")->second;
    DrawComponment *dc = new DrawComponment(pModelSpace,this->windowData,3);
    int offset = 500;
    QPointF startPoint_view0(100,100);
    QPointF startPoint_view1(100,100 + offset);
    QPointF startPoint_view2(100 + offset,100 + offset);
    //画俯视图
    dc->DrawLBoard(startPoint_view0,0);
    startPoint_view0 = QPointF(startPoint_view0.x() + lboardLHeight,startPoint_view0.y() + lboardLHeight);
    dc->DrawEdge(startPoint_view0,0);
    //画正视图
    dc->DrawLBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + lboardLHeight,startPoint_view1.y() + lboardLHeight);
    dc->DrawEdge(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x() + hidePlainEdgeWidth,startPoint_view1.y());
    dc->DrawBoard(startPoint_view1,1);
    startPoint_view1 = QPointF(startPoint_view1.x(),startPoint_view1.y() + upperBoardWidth - boardSlotDept);
    dc->DrawLeaf(startPoint_view1,1);
    //画侧视图
    dc->DrawLBoard(startPoint_view2,2);
    startPoint_view2 = QPointF(startPoint_view2.x() + upperBoardHeight - lboardLHeight ,startPoint_view2.y() + (leftLBoardLength - plainEdgeLength));
    dc->DrawBoard(startPoint_view2,2);
    dc->DrawLeaf(startPoint_view2,2);
    if (isExport) pDoc->dynamicCall("SaveAs(const QString&)",exportPath);
}
void DrawWindow::Draw()
{
  switch (type) {
    case 0:
      DrawSingleWindow();
      qDebug() << "singleWindow";
        break;
    case 1:
      DrawDoubleWindow();
      qDebug() << "doubleWindow";
        break;
    case 2:
      DrawTripleWindow();
      qDebug() << "tripleWindow";
        break;
    }
}
